Skip to content

fix(s09): re-locate the memory turn by identity after compaction instead of a stale index - #497

Closed
ClearVIper3 wants to merge 1 commit into
shareAI-lab:mainfrom
ClearVIper3:fix/s09-memory-index-drift
Closed

fix(s09): re-locate the memory turn by identity after compaction instead of a stale index#497
ClearVIper3 wants to merge 1 commit into
shareAI-lab:mainfrom
ClearVIper3:fix/s09-memory-index-drift

Conversation

@ClearVIper3

Copy link
Copy Markdown
Contributor

The memory injection turn was located by a pre-compaction index that
compaction then shifted, so memory was silently dropped whenever
compaction fired. Re-locate the user turn by object identity after each
compaction step instead of trusting the stale index; leave the
compaction functions untouched.

Fixes #496

  `memory_turn` was computed once as `len(messages) - 1` *before* the s08
  compression pipeline runs. `snip_compact` / `compact_history` /
  `reactive_compact` shorten or rebuild the message list, so the index
  drifts: the guard `memory_turn < len(messages)` then fails and the memory
  injection is silently skipped — precisely when compaction triggers (long
  conversations), i.e. when the memory system is supposed to matter most.

  Fix: capture the user-turn *object* and re-locate it by identity after
  each compaction step via the new `_find_memory_turn`, falling back to the
  last str-content user turn if the query was summarized away. No change to
  the s08 compaction functions — the bug was entirely in agent_loop.
@Bill-Billion

Copy link
Copy Markdown
Collaborator

Thanks for identifying and fixing the stale memory_turn index in the previous s09 implementation. The issue was valid for that version.

Since then, s09 has been refactored to load relevant memories directly into the system prompt and no longer uses a pre-compaction message index. The same index-based path has also been removed from the integrated implementation.

Since the original issue no longer exists on main and this PR now conflicts with the current architecture, I’m closing it as superseded. Thanks again for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

s09_memory:snip_compact 触发后 引发 memory_turn 索引漂移,该轮已检索到的记忆没注入进 prompt

2 participants